import React from 'react';
import { HashRouter as Router, Route, Redirect, Switch } from 'react-router-dom'
import { withRouter } from 'react-router-dom';
import { Provider, inject, observer } from 'mobx-react';
import { asyncComponent } from 'react-async-component';
import { Tools } from 'weaver-mobile';
import { DocumentTitle } from "weaver-mobile-page";
import dict from '../../util/wea-workrelate-file';
const getLabel = Tools.getLabel;
dict.addWindowFunc();
const coms = {
  GoalMain: asyncComponent({
    resolve: () => import('./GoalMain')
  }),
  GoalMainAdvancedSearch: asyncComponent({
    resolve: () => import('./goalMainAdvancedSearch/GoalMainAdvancedSearch')
  }),
  GoalAdd: asyncComponent({
    resolve: () => import('./GoalAdd')
  }),
  GoalDetail: asyncComponent({
    resolve: () => import('./goalDetail/GoalDetail')
  }),

}
@inject('goalMainStore')
@withRouter
@observer
class Index extends React.Component {

  constructor(props){
    super(props);
  }

  getCondtypeTitle = (condtype) => {
    const { condTypeOptions } = this.props.goalMainStore
    let title = ""
    condTypeOptions.forEach((d, i) => {
      if (d.key == condtype) {
        title = d.menuname
      }
    })
    return title
  }


  render() { 
    const { condtype } = this.props.goalMainStore
    const data = [
      { match: /^\/goalHome\/goalMain/i, title: () => this.getCondtypeTitle(condtype) },
      { match: /^\/goalHome\/mainAdvancedSearch/i, title: () => getLabel(347,'高级搜索') },
      { match: /^\/goalHome\/goalAdd/i, title: () => getLabel(508587,'新建目标') },
      { match: /^\/taskHome\/taskMain\/tagManage/i, title: () => getLabel(30884,'标签设置') },
      { match: /^\/goalHome\/goalDetail/i, title: () => getLabel(507890,'目标详情') }
    ]
      return (
      //   <Switch>
      //     <Route name='goalHome' breadcrumbName="目标" path='/goalHome' render={() => {
      //       return (
      //         <coms.GoalMain>
      //           <Switch>
      //             {/* <Route name='taskMainAdvancedSearch' breadcrumbName='首页高级搜索' path='/taskHome/mainAdvancedSearch' component={coms.TaskMainAdvancedSearch} /> */}
      //             <Route name='goalAdd' breadcrumbName='新建目标' path='/goalHome/goalAdd' component={coms.GoalAdd} />
      //             <Route name='goalDetail' breadcrumbName='目标详情主页' path='/goalHome/goalDetail/:id' component={coms.GoalDetail} />
      //           </Switch>
      //         </coms.GoalMain>
      //       )
      //     }} />
      // </Switch>
      <div style={{height:"100%"}}>
           <DocumentTitle data={data} defaultTitle="" />
            <Switch>
                <Route id="goalMain"
                        breadcrumbName={getLabel(330,'目标')}
                        path="/goalHome/goalMain/:condtype"
                        component={coms.GoalMain}/>
                <Route id="goalAdd"
                        breadcrumbName={ getLabel(508587,'新建目标')}
                        path="/goalHome/goalAdd"
                        component={coms.GoalAdd}/>
                <Route id="goalDetail"
                        breadcrumbName={getLabel(507890,'目标详情')}
                        path="/goalHome/goalDetail"
                        component={coms.GoalDetail}/>    
                <Route id="goalMainAdvancedSearch"
                        breadcrumbName={getLabel(347,'高级搜索')}
                        path="/goalHome/mainAdvancedSearch"
                        component={coms.GoalMainAdvancedSearch}/>   
                        
                <Redirect exact path="/goalHome" to={{pathname: '/goalHome/goalMain/'+ condtype}}/>
            </Switch>
      </div>
   
      )
    }
  }
  
  export default Index;